/*
 * Name     : Packet.java
 * Author(s): Jill San Luis
 * Created  : Mar 14, 2011, 3:01:59 PM
 */
package mazewar.packet;

/**
 * The Packet class
 *
 * @author  Jill San Luis
 */
public class Packet {

    private static final String DELIMITER = "::";
    private PacketType type;
    private PacketAction action;
    private String srcIP;
    private int srcPort = -1;
//    private String dstIP;
//    private int dstPort = -1;

    /**
     * Creates a new instance of Packet.
     */
    public Packet(String ip, int port, PacketType type, PacketAction action) {
        this.srcIP = ip;
        this.srcPort = port;
        this.type = type;
        this.action = action;
    }

    /**
     * @return the type
     */
    public PacketType getType() {
        return type;
    }

    /**
     * @return the action
     */
    public PacketAction getAction() {
        return action;
    }

    /**
     * @return the srcIP
     */
    public String getIp() {
        return srcIP;
    }

    /**
     * @return the srcPort
     */
    public int getPort() {
        return srcPort;
    }

    public String compress(){

        if(srcIP == null || srcPort <0 || action== null || type == null){
            return null;
        }

        return srcIP + DELIMITER + srcPort + DELIMITER + type + DELIMITER + action;
    }
}
